package com.tt5.services.vertx

import io.vertx.core.Future
import io.vertx.redis.client.Command
import io.vertx.redis.client.RedisAPI
import io.vertx.redis.client.RedisConnection
import io.vertx.redis.client.Request
import io.vertx.redis.client.Response

val RedisConnection.api: RedisAPI
    get() = RedisAPI.api(this)

fun RedisConnection.set(key: String, value: String): Future<Response?> {
    return send(
        Request.cmd(Command.SET).arg(
            if (!key.startsWith(redisKeyPrefix)) "${redisKeyPrefix}${key}" else key
        ).arg(value)
    )
}

fun RedisConnection.get(key: String): Future<Response?> {
    return send(
        Request.cmd(Command.GET).arg(
            if (!key.startsWith(redisKeyPrefix)) "${redisKeyPrefix}${key}" else key
        )
    )
}

fun RedisConnection.delete(key: String): Future<Response?> {
    return send(
        Request.cmd(Command.DEL).arg(
            if (!key.startsWith(redisKeyPrefix)) "${redisKeyPrefix}${key}" else key
        )
    )
}
